<template>
	<view class="">

		<view class="index-coupon">
			<scroll-view scroll-x="true" class="index-coupon-view">
				<view class="index-coupon-msg" v-for="(item,index ) in clist" :key="index">
					<view class="index-coupon-msg-msg" :class="activeTabIndex==index?'activeTab':''"
						@click="manuBtn(index,item)">
						{{item.name}}
					</view>
				</view>
			</scroll-view>

		</view>
		<view class="" style="height: 130rpx;">

		</view>
		<view class="list">
			<!-- {{type==1?'村规明月传的':'通知公告穿的'}}这个页面穿的 -->
			<view class="list-msg" v-for="(item,index) in list" :key="index" @click="goPage(item)">
				{{index+1}}、{{item.title}}
			</view>
		</view>
		<home></home>
	</view>
</template>

<script>
	import home from '@/components/home/index.vue'
	import {
		getH5List,
		newsGetCategory,
		newsgetH5List,
		ruleGetCategory
	} from '@/api/togeterRich/family.js'
	export default {
		components:{
			home
		},
		data() {
			return {
				cData: {},
				clist: [],
				list: [],
				activeTabIndex: 0,
				type: null,
			}
		},
		onLoad(e) {

			this.type = e.type
			if (this.type == 1) {

				uni.setNavigationBarTitle({
					title: '村规民约'
				});

			} else if (this.type == 2) {

				uni.setNavigationBarTitle({
					title: '通知公告'
				});
			}
			this.init()
			uni.hideLoading()

		},
		methods: {
			init() {
				if (this.type == 1) {
					ruleGetCategory().then(res => {

						this.clist = res.data
						this.cData = this.clist[0]
						this.cgmyInit()
					})

				} else if (this.type == 2) {
					newsGetCategory().then(res => {
						this.clist = res.data
						this.cData = this.clist[0]
						this.initList()

					})
					uni.setNavigationBarTitle({
						title: '通知公告'
					});
				}

			},
			cgmyInit() {
				let data = {
					cid: this.cData.id
				}
				getH5List(data).then(res => {
					this.list = res.data

				})
			},

			initList() {
				let data = {
					cid: this.cData.id
				}
				newsgetH5List(data).then(res => {
					this.list = res.data

				})
			},
			goPage(item) {
				// 1
				uni.navigateTo({
					url: `/pagesA/villagers/info?type=${this.type}&&id=${item.id}`
				})
			},
			manuBtn(index, item) {
				this.cData = item
				this.activeTabIndex = index
				if (this.type == 1) {
					this.cgmyInit()

				} else if (this.type == 2) {
					this.initList()
				}


			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		width: 100%;
		background: #fff;

		.list-msg {
			width: 90%;
			height: 100rpx;
			line-height: 100rpx;
			margin: 0 auto;
			border-bottom: 1rpx solid #999;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			// padding: 30rpx;/
		}
	}

	.activeTab {
		border-bottom: 4rpx solid $maincolor;
		color: $maincolor;
	}

	.index-coupon {
		position: fixed;
		top: 0;
		width: 100%;
		padding: 13px 20rpx;
		border-radius: 10rpx;

		background: #fff;
		display: flex;
		justify-content: space-between;
		align-items: baseline;


		.index-coupon-view {
			white-space: nowrap;
			padding: 15rpx 0;
			margin: 0 auto;

			.index-coupon-msg {
				.index-coupon-msg-msg {
					color: $maincolor;
					padding: 8rpx 20rpx;
					color: #000;

				}

				display: inline-block;
				opacity: 1;
				margin-right: 50rpx;
			}
		}


	}
</style>